<?php

/**
 * Index controller class
 *
 */

class NovostiController extends Client_Controller
{
	public function init()
    {
        parent::init();
        $this->setActiveCat(883);
    }

    public function indexAction()
    {
    	$page = $this->_getParam('page', 1);
    	$this->startContent();
	        $this->view->xmlWriter->startElement("Main");
			$this->view->assign('list', $this->table_articles->GetDataList($page, array('id_cat' => 772)));
		    $this->view->xmlWriter->endElement();
	    $this->view->xmlWriter->endElement();
    }

    public function viewAction()
    {
    	$id = $this->_getParam('id');
    	$id_cat = $this->_getParam('cat');
    	$page = $this->_getParam('page', 1);
		if(is_null($id) && is_null($id_cat)) $this->_redirect('/'.$this->controller);

		$data = $this->table_articles->GetDataRow($id);
		//if(!isset($data['id'])) $this->_redirect('/'.$this->controller);//$this->_redirect('/error/e404');
		$params = array();

		$cat = $this->table_categories->GetDataRow($id_cat);
		if(isset($cat['id'])) $this->setActiveCat($cat['id']);

		if(!isset($data['id']))
		{

			if(isset($cat['id']))
			{
				$params = array('id_cat' => $cat['id'], 'type' => 0);
				$list = $this->table_articles->GetDataList($page, $params);
			}
		}

		 if(isset($data['id'])) $this->setCEO($data);



		 //$this->setActiveCat($cat['id']);

    	$this->startContent();
	        $this->view->xmlWriter->startElement("Main");
	        if(isset($data['id']))
	        {
	        	$this->setCEO($data);
	        	$this->view->assign('data', $data);
	        	if($data['is_show_gallery'])  $this->view->assign('attaches', $this->table_objects->GetDataList(array('id_article' => $data['id'])));
	        	$this->view->assign('nextback', $this->table_articles->GetNextBack($data['id'], array('id_cat' => $data['id_cat'])));
	        	//$this->view->assign('last', $this->table_articles->GetLast(array('except' => $data['id'], 'type' => 0), 3));
	        }

	        if(isset($list))	$this->view->assign('list', $list);
		    $this->view->xmlWriter->endElement();
	    $this->view->xmlWriter->endElement();


    }



}
